package StatisticsController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.commons.util.Encrypt;
import com.renjun.smweb.controller.StatisticsController.StatisticsController;
import com.renjun.smweb.dao.pojo.LoginInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by RenJun on 2017/3/6.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath*:/spring-mvc.xml", "classpath*:/spring-mybatis.xml"})
public class StatisticsControllerTestCase {


    //模拟request,response
    private MockHttpServletRequest request;
    private static MockHttpServletResponse response;

    @Autowired
    private StatisticsController statisticsController;

    @Before
    public void setUp() throws Exception {
        request = new MockHttpServletRequest();
        request.getSession().setAttribute("userinfo", getLoginInfo());
//        response = new MockHttpServletResponse();
    }

    @Test
    public void testHomeStatistics() {
        System.out.println("查询首页统计数据");
        //查询首页统计数据
        Map<String,Object> params = new HashMap<>();
//        params.put("djxx","3101160001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.homeStatistics(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void registerStatisticsByQxXb() {
        System.out.println("报名登记统计（区县小班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.registerStatisticsByQxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expRegisterStatisticsByQxXb() {
        System.out.println("报名登记统计导出（区县小班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expRegisterStatisticsByQxXb(request,response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }



    @Test
    public void registerStatisticsByQxTb() {
        System.out.println("报名登记统计（区县托班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.registerStatisticsByQxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expRegisterStatisticsByQxTb() {
        System.out.println("报名登记统计导出（区县托班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expRegisterStatisticsByQxTb(request,response);
        String jiem = (String) rs.get("response");
        System.out.println("\n json对象：" + Encrypt.jiem(jiem)+ "\n");
    }

    @Test
    public void registerStatisticsByXxXb() {
        System.out.println("报名登记统计（学校小班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.registerStatisticsByXxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expRegisterStatisticsByXxXb() {
        System.out.println("报名登记统计导出（学校小班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expRegisterStatisticsByXxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void registerStatisticsByXxTb() {
        System.out.println("报名登记统计（学校托班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.registerStatisticsByXxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expRegisterStatisticsByXxTb() {
        System.out.println("报名登记统计导出（学校托班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expRegisterStatisticsByXxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }


    @Test
    public void admissionStatisticsByQxXb() {
        System.out.println("录取统计（区县小班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.admissionStatisticsByQxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expAdmissionStatisticsByQxXb() {
        System.out.println("录取统计导出（区县小班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expAdmissionStatisticsByQxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void admissionStatisticsByQxTb() {
        System.out.println("录取统计（区县托班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.admissionStatisticsByQxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expAdmissionStatisticsByQxTb() {
        System.out.println("录取统计导出（区县托班）");
        Map<String,Object> params = new HashMap<>();
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expAdmissionStatisticsByQxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void admissionStatisticsByXxXb() {
        System.out.println("录取统计（学校小班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.admissionStatisticsByXxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expAdmissionStatisticsByXxXb() {
        System.out.println("录取统计导出（学校小班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expAdmissionStatisticsByXxXb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void admissionStatisticsByXxTb() {
        System.out.println("录取统计（学校托班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.admissionStatisticsByXxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    @Test
    public void expAdmissionStatisticsByXxTb() {
        System.out.println("录取统计导出（学校托班）");
        Map<String,Object> params = new HashMap<>();
        params.put("schoolcode","31011600001");
        request.setContent(JSONObject.toJSONString(params).getBytes());
        JSONObject rs = statisticsController.expAdmissionStatisticsByXxTb(request,response);
        String str = JSON.toJSONString(rs);
        System.out.println("\n json对象：" + str + "\n");
    }

    /**
     *   获取缓存LoginInfo
     */
    private LoginInfo getLoginInfo() {
        LoginInfo loginInfo = new LoginInfo();
        loginInfo.setId("测试人员");
        loginInfo.setRoleid("2");
        loginInfo.setDistrictcode("310116");
        loginInfo.setRoletype("2");
        loginInfo.setUsername("测试123");
        loginInfo.setRealname("junit测试管理员");
        return loginInfo;
    }

}
